<template>
  <van-address-edit
    :area-list="areaList"
    :address-info="addresseditinfo"
    show-postal
    show-set-default
    show-search-result
    :search-result="searchResult"
    :area-columns-placeholder="areacolumnsplaceholder"
    @save="onSave"
  />
</template>

<script>
  import request, { getUrl } from "../../utils/request";
  import { areaList } from '@vant/area-data';
  import {removeStorageToken,getStorageUser,setStorageUser} from "@/utils/storage.js"//导入
  import { showDlg } from "../../utils/tools";
  export default{
    data() {
      return{
        areaList,
        addresseditinfo:{//编辑器的数据
          name:"",
          tel:"",
          areaCode:"",//地区编码
          province:"",
          city:"",
          county:"",
          addressDetail:"",
          postalCode:"",//邮政编码
          isDefault:false
        }
      }
    },
    methods:{
      onSave(val){//保存
        var isdef=0
        if(val.isDefault==true){//根据传入的参数修改默认值
          isdef=1
        }
        var that = this
        request({//页面加载的时候 发起请求
          url:getUrl("User/addUserAdd"),//URL
          method:"post",//请求方法
          headers: {
                  'Content-Type': 'application/x-www-form-urlencoded'
          },
          data:{
            uname:val.name,
            tel:val.tel,
            province:val.province,
            city:val.city,
            county:val.county,
            areacode:val.areaCode,
            address:val.addressDetail,
            isdef:isdef,
            code:val.postalCode,
            uid:getStorageUser().id
          }
        }).then(res=>{
          if(res.data.code==0){
            showDlg("操作提示","添加成功！")
            this.$router.push("/addresslist")//跳转到列表页
          }else{
            showDlg("操作提示","添加失败！")
          }
        })
        .catch(error=>{
            showDlg("操作提示","修改失败！")
        })
      }
    }
  }
</script>

<style>
</style>
